package javase.collection.list;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试 {@link java.util.ArrayList#subList(int, int)}方法
 *
 * @author hck
 */
public class TestSubList {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>(4);
        for (int i = 0; i < 4; i++) {
            list.add(i);
        }
        System.out.println("parent list:");
        System.out.println(list.toString());
        System.out.println("hash code:" + list.hashCode());
        System.out.println("---------------");

        System.out.println("sub list:");
        List<Integer> subList = list.subList(1, 2);
        System.out.println(subList.toString());
        System.out.println("hash code:" + subList.hashCode());
        System.out.println("---------------");
        System.out.println("subList add 3 element:");
        subList.add(-1);
        subList.add(-2);
        subList.add(-3);
        System.out.println("sublist:" + subList);
        System.out.println("parentList:" + list);
        System.out.println("---------------");
        System.out.println("clear sub list");
        subList.clear();
        System.out.println("parent list:" + list);
        System.out.println("sublist" + subList);
        System.out.println("---------------");
        System.out.println("subList add 1 element");
        subList.add(1);
        System.out.println("parent list:" + list);
        System.out.println("sublist" + subList);
        System.out.println("---------------");
        System.out.println("subList set index 0 with -1");
        subList.set(0, -1);
        System.out.println("parent list:" + list);
        System.out.println("sublist" + subList);

        System.out.println("---------------");
        System.out.println("parent list modify add element 10");
        list.set(1, 9);
        System.out.println("parent list:" + list);
        System.out.println("sublist" + subList);

        System.out.println("---------------");
        System.out.println("parent list modify add element 10");
        list.add(10);
        System.out.println("parent list:" + list);
        System.out.println("sublist" + subList);
    }
}
